package com.usian.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.pojo.Dept;
import com.usian.pojo.Emp;
import com.usian.pojo.Posts;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

public interface PostsMapper extends BaseMapper<Posts> {
    //获取职位级别
    @Select("SELECT e.*,p.code grade FROM emp e LEFT JOIN posts p ON e.pid=p.id WHERE e.id=#{id}")
    Emp findById(Integer id);
    //查询1
    Page<Posts> findPage1(Page<Posts> page1, String name, Integer code, Integer did, Integer id);
    //查询2
    Page<Posts> findPage2(Page<Posts> page1, String name, Integer code, Integer did, Integer id);
    //根据名称查询
    @Select("select count(*) from posts where name=#{name} and did=#{did} and id !=#{id}")
    Integer findByName1(Integer id,String name,Integer did);
    //根据名称查询
    @Select("select count(*) from posts where name=#{name} and did=#{did}")
    Integer findByName(String name,Integer did);
    //根据部门查询所有职位
    @Select("SELECT id,NAME FROM posts WHERE did=#{did}")
    List<Posts> findByList(Integer did);
    //获取职位级别
    @Select("select code from posts where id=#{pid}")
    Integer findByCode(Integer pid);
    //查询职位人数
    @Select("SELECT COUNT(*) FROM emp e,posts p WHERE e.pid=p.id AND p.id=#{id}")
    Integer findCount(Integer id);
    //根据ID查询职位名称
    @Select("select name from posts where id=#{id}")
    String findByName2(Integer id);
    //根据职位查询是否有员工
    @Select("SELECT COUNT(*) FROM emp e,posts p WHERE e.pid =p.id AND e.pid = #{id}")
    Integer findByEname(Integer ids);
}
